home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / c / wind_src.lha / window.c < prev    next >
C/C++ Source or Header  |  1995-09-06  |  7KB  |  266 lines

  1. /*
  2.     window.c
  3.     WindowDemo - COOL !
  4.  
  5.     Manx Aztec C V5.0
  6.     Tuesday, October 8, 1991
  7.  
  8.     Coded by Sentinel
  9.     # CRO 042 691 567
  10. */
  11.  
  12. /***************************************************************************/
  13.  
  14. #include <ctype.h>
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17.  
  18. #include <graphics/gfxbase.h>
  19. #include <graphics/gfx.h>
  20.  
  21. #include <intuition/intuitionbase.h>
  22. #include <intuition/intuition.h>
  23.  
  24. /***************************************************************************/
  25.  
  26. #define WIN_WIDTH    640
  27. #define WIN_HEIGHT    256
  28.  
  29. #define MIN_WIDTH    175
  30. #define MIN_HEIGHT    52
  31.  
  32. #define MAX_WIDTH    640
  33. #define MAX_HEIGHT_PAL    256
  34. #define MAX_HEIGHT_NTSC    200
  35.  
  36. /***************************************************************************/
  37.  
  38. void adios(char *message);
  39. void about(void);
  40. long asker(void);
  41.  
  42. /***************************************************************************/
  43.  
  44. struct GfxBase        *GfxBase;
  45. struct IntuitionBase    *IntuitionBase;
  46.  
  47. struct Window        *window;
  48. struct RastPort        *rastport;
  49. struct IntuiMessage    *intuimessage;
  50.  
  51. /***************************************************************************/
  52. struct TextAttr T8 = { (UBYTE *)"topaz.font", 8, 0, 0 };
  53.  
  54. static char winstring[] = "1991 By SENTINEL";
  55. struct IntuiText wintext = { 3, 0, JAM1, 0, 0, &T8, (UBYTE *)&winstring, 0 };
  56.  
  57. /***************************************************************************/
  58.  
  59. static char WindowTitle[] = "WindowDemo";
  60. struct NewWindow newwindow = {    0, 0, WIN_WIDTH, WIN_HEIGHT, 0, 1,
  61.                 CLOSEWINDOW|MENUPICK,
  62.                 WINDOWCLOSE|WINDOWSIZING|WINDOWDRAG
  63.                 |WINDOWDEPTH|ACTIVATE|NOCAREREFRESH,
  64.                 (struct Gadget *)NULL,
  65.                 (struct Image *)NULL,
  66.                 (UBYTE *)WindowTitle,
  67.                 (struct Screen *)NULL,
  68.                 (struct BitMap *)NULL,
  69.                 MIN_WIDTH, MIN_HEIGHT, MAX_WIDTH,
  70.                 MAX_HEIGHT_PAL, WBENCHSCREEN };
  71.  
  72. /***************************************************************************/
  73.  
  74. struct IntuiText intuitext1 = { 0, 1, JAM1, 8, 1, &T8, (UBYTE *)"About", 0 };
  75. struct IntuiText intuitext2 = { 0, 1, JAM1, 0, 1, &T8, (UBYTE *)"-------", 0 };
  76. struct IntuiText intuitext3 = { 0, 1, JAM1, 8, 1, &T8, (UBYTE *)"Quit", 0 };
  77.  
  78. struct MenuItem menuitem1 = {     NULL,
  79.                 2, 0, 56, 10,
  80.                 ITEMTEXT|ITEMENABLED|HIGHCOMP, 0L,
  81.                 (APTR)&intuitext1,
  82.                 (APTR)0, (BYTE)0, (struct MenuItem *)0,
  83.                 (USHORT)0 };
  84.  
  85. struct MenuItem menuitem2 = {     (struct MenuItem *)&menuitem1,
  86.                 2, 10, 56, 10,
  87.                 ITEMTEXT|HIGHCOMP, 0L,
  88.                 (APTR)&intuitext2,
  89.                 (APTR)0, (BYTE)0, (struct MenuItem *)0,
  90.                 (USHORT)0 };
  91.  
  92. struct MenuItem menuitem3 = {     (struct MenuItem *)&menuitem2,
  93.                 2, 19, 55, 10,
  94.                 ITEMTEXT|ITEMENABLED|HIGHBOX, 0L,
  95.                 (APTR)&intuitext3,
  96.                 (APTR)0, (BYTE)0, (struct MenuItem *)0,
  97.                 (USHORT)0 };
  98.  
  99. struct Menu menu = {        NULL,
  100.                 0, 0,
  101.                 62, 10,
  102.                 MENUENABLED,
  103.                 (BYTE *) "Options",
  104.                 &menuitem3,
  105.                 0, 0, 0, 0 };
  106.  
  107. /***************************************************************************/
  108.  
  109. UWORD pointer_data[] ={    0, 0, 256, 256, 256, 256, 896, 0, 3168, 0, 12312, 0,
  110.             256, 49414, 256, 49414, 12312, 0, 3168, 0, 896, 0,
  111.             256, 256, 256, 256, 256, 256, 0, 0 };
  112.  
  113. UWORD *chip_data;
  114.  
  115. /***************************************************************************/
  116.  
  117. ULONG class;
  118. USHORT code;
  119. BOOL quit=FALSE;
  120. short count;
  121.  
  122. /***************************************************************************/
  123.  
  124. void main(void)
  125. {
  126.  
  127. GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L);
  128. if (!GfxBase) adios("ERROR: Couldn't open graphics.library !");
  129.  
  130. IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0L);
  131. if (!IntuitionBase) adios("ERROR: Couldn't open intuition.library !");
  132.  
  133. chip_data = (UWORD *) AllocMem(sizeof(pointer_data), MEMF_CHIP);
  134. if (!chip_data) adios("ERROR: Couldn't allocate memory for chip_data");
  135.  
  136. for (count = 0; count <32; count++)
  137.     *(chip_data+count) = pointer_data[count];
  138.  
  139. if (GfxBase -> DisplayFlags == 1)
  140.     newwindow.MaxHeight = newwindow.Height = MAX_HEIGHT_NTSC;
  141.  
  142. window = (struct Window *) OpenWindow(&newwindow);
  143. if (!window) adios("ERROR: Not enough memory for main-window.");
  144.  
  145. rastport=window->RPort;
  146. PrintIText(rastport, &wintext, 25, 25);
  147.  
  148. SetPointer(window, (short *) chip_data, 14, 16, -7, -6);
  149. SetMenuStrip(window, &menu);
  150.  
  151. while (!quit) {
  152.     intuimessage = (struct IntuiMessage *) GetMsg(window->UserPort);
  153.  
  154.     if (intuimessage == NULL)
  155.         continue;
  156.  
  157.     class = intuimessage->Class;
  158.     code = intuimessage->Code;
  159.  
  160.     switch (class) {
  161.         case CLOSEWINDOW :
  162.             quit = (BOOL) asker();
  163.             break;
  164.  
  165.         case MENUPICK :
  166.             if (MENUNUM(code)==0)
  167.                 switch(ITEMNUM(code)) {
  168.                     case 2:    about();
  169.                         break;
  170.  
  171.                     case 0:    quit=(BOOL) asker();
  172.                 }
  173.         }
  174.  
  175.     ReplyMsg(intuimessage);
  176.     }
  177.  
  178. ClearMenuStrip(window, &menu);
  179. ClearPointer(window);
  180.  
  181. adios(NULL);
  182. }
  183.  
  184. /***************************************************************************/
  185.  
  186. void adios(char *message)
  187. {
  188.     if(message)        puts(message);
  189.     if(chip_data)        FreeMem(chip_data, sizeof(pointer_data));
  190.     if(window)        CloseWindow(window);
  191.     if(IntuitionBase)    CloseLibrary(IntuitionBase);
  192.     if(GfxBase)        CloseLibrary(GfxBase);
  193.     if(message)        exit(1);
  194. }
  195.  
  196. /***************************************************************************/
  197.  
  198. void about(void)
  199. {
  200.  
  201.     static char title[] = "About WindowDemo";
  202.     static char text1[] = " WindowDemo Version 1.0b";
  203.     static char text2[] = "   (c)1991 By Sentinel";
  204.     static char text3[] = "Call me: CRO #042 691 567";
  205.  
  206.     struct Window        *wd;
  207.     struct RastPort        *rp;
  208.     struct IntuiMessage    *im;
  209.  
  210.     static struct IntuiText it3 = { 1, 0, JAM1, 5, 24, &T8,
  211.         (UBYTE *)text3, (struct IntuiText *)NULL };
  212.  
  213.     static struct IntuiText it2 = { 2, 0, JAM1, 5, 12, &T8,
  214.         (UBYTE *)text2, (struct IntuiText *)&it3 };
  215.  
  216.     static struct IntuiText it1 = { 3, 0, JAM1, 5, 0, &T8,
  217.         (UBYTE *)text1, (struct IntuiText *)&it2 };
  218.  
  219.     static short coords[] = { 1, 1, 238, 1, 238, 50, 1, 50, 1, 1 };
  220.     static struct Border brdr = { 0, 0, 3, 0, JAM1, 5, &coords[0], NULL };
  221.  
  222.     struct NewWindow nw = {    15, 15, 251, 65, 0, 1,
  223.                 CLOSEWINDOW|MOUSEBUTTONS,
  224.                 WINDOWCLOSE|WINDOWDRAG|ACTIVATE|RMBTRAP,
  225.                 (struct Gadget *)NULL,
  226.                 (struct Image *)NULL,
  227.                 (UBYTE *)title,
  228.                 (struct Screen *)NULL,
  229.                 (struct BitMap *)NULL,
  230.                 0, 0, 0, 0, WBENCHSCREEN };
  231.  
  232.  
  233.     wd = (struct Window *) OpenWindow (&nw);
  234.     if (wd) {
  235.         rp=wd->RPort;
  236.         PrintIText(rp, &it1, 20, 20);
  237.         DrawBorder(rp, &brdr, 6, 11);
  238.  
  239.         while (im->Class != CLOSEWINDOW && im->Class != MOUSEBUTTONS)
  240.             im = (struct IntuiMessage *) GetMsg(wd->UserPort);
  241.         ReplyMsg(im);
  242.         CloseWindow(wd);
  243.         }
  244.     else
  245.         adios("ERROR: Not enough memory for about-window");
  246. }
  247.  
  248. /***************************************************************************/
  249.  
  250. long asker(void)
  251. {
  252.  
  253.     static struct IntuiText BodyText = {0, 1, JAM1, 20, 4, &T8,
  254.         (UBYTE *)"Are you sure ?", NULL};
  255.  
  256.     static struct IntuiText PosText = {0, 1, JAM1, 6, 4, &T8,
  257.         (UBYTE *)"Yes", NULL};
  258.  
  259.     static struct IntuiText NegText = {0, 1, JAM1, 7, 4, &T8,
  260.         (UBYTE *)"No", NULL};
  261.  
  262.  
  263.     return(AutoRequest (window, &BodyText, &PosText, &NegText,
  264.         0, 0, 170, 50));
  265. }
  266.